//
//  NoDataView.m
//  Btpin
//
//  Created by Vic on 2019/3/10.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "NoDataView.h"

@interface NoDataView ()
{
    UIImageView *noDataImgView;
    UILabel *noDataLbl;
    UILabel *btnLbl;
}
@end

@implementation NoDataView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
        self.hidden = YES;
        self.userInteractionEnabled = NO;
    }
    return self;
}
- (void)initUI {
    noDataImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(0, 0, 0.1, 0.1) imageName:nil];
    noDataImgView.userInteractionEnabled = NO;
    [self addSubview:noDataImgView];
    noDataLbl = [UIToolsControl initLabelWithFrame:CGRectMake(0, EndY(noDataImgView)+10*Scale, self.frame.size.width, 20*Scale) text:nil textColor:THEMECOLOR_OF_TEXT_9a9a9a font:Font_15];
    noDataLbl.textAlignment = NSTextAlignmentCenter;
    noDataLbl.userInteractionEnabled = NO;
    noDataLbl.numberOfLines = 0;
    noDataLbl.lineBreakMode = NSLineBreakByWordWrapping;
    [self addSubview:noDataLbl];
    
    btnLbl = [UIToolsControl initLabelWithFrame:CGRectMake(110*Scale, EndY(noDataLbl)+15*Scale, self.frame.size.width-220*Scale, 50*Scale) text:nil textColor:THEMECOLOR_OF_ORANGE font:Font_18];
    btnLbl.font = FontBold(Font_18);
    btnLbl.textAlignment = NSTextAlignmentCenter;
    btnLbl.userInteractionEnabled = NO;
    btnLbl.layer.borderWidth = 1;
    btnLbl.layer.borderColor = THEMECOLOR_OF_ORANGE.CGColor;
    btnLbl.layer.cornerRadius = 25*Scale;
    btnLbl.layer.masksToBounds = YES;
    [self addSubview:btnLbl];
    btnLbl.hidden = YES;
}
- (void)setText:(NSString *)text {
    noDataLbl.text = text;
}
- (void)setImgName:(NSString *)imgName {
    UIImage *image = [UIImage imageNamed:imgName];
    noDataImgView.image = image;
}
- (void)vcNilStatusType:(VCNilStatusType)vcNilStatusType superView:(UIView *)superView {
    [superView bringSubviewToFront:self];
    self.hidden = NO;
    btnLbl.hidden = YES;
    NSString *imgName = @"no_commondata_icon";
    NSString *text = @"暂无数据";
    CGFloat y = 60*Scale;
    CGFloat yNoDataLbl = EndY(noDataImgView)+10*Scale;
    CGFloat textHeight = 20*Scale;
    switch (vcNilStatusType) {
        case VCNilStatusTypeOfDefault: { // 默认
            imgName = @"no_net_icon";
            text = @"网络好像断开了呢";
            y = 60*Scale;
            textHeight = 20*Scale;
            self.userInteractionEnabled = YES;
            
            UIImage *imgTemp = [UIImage imageNamed:imgName];
            yNoDataLbl = y+imgTemp.size.height*0.5+10*Scale;
        } break;
        case VCNilStatusTypeOfNoNet: { // 没有网络
            imgName = @"no_net_icon";
            text = @"网络好像断开了呢";
            y = 60*Scale;
            textHeight = 20*Scale;
            self.userInteractionEnabled = YES;
            
            UIImage *imgTemp = [UIImage imageNamed:imgName];
            yNoDataLbl = y+imgTemp.size.height*0.5+10*Scale;
        } break;
        case VCNilStatusTypeOfWorkerList: { // 人才列表空
            imgName = @"no_worker_icon";
            text = @"暂无符合条件的人才";
            y = 35*Scale;
            textHeight = 20*Scale;
            self.userInteractionEnabled = NO;
            
            UIImage *imgTemp = [UIImage imageNamed:imgName];
            yNoDataLbl = y+imgTemp.size.height+10*Scale;
        } break;
        case VCNilStatusTypeOfWorkerCollect: { // 人才收藏空
            imgName = @"no_worker_icon";
            text = @"目前您没有收藏人才！\n\n找优秀人才，我们建议您主动出击。";
            y = 190*Scale;
            textHeight = 60*Scale;
            self.userInteractionEnabled = YES;
            btnLbl.hidden = NO;
            btnLbl.text = @"去查看人才";
            
            UIImage *imgTemp = [UIImage imageNamed:imgName];
            yNoDataLbl = y+imgTemp.size.height+10*Scale;
        } break;
        case VCNilStatusTypeOfCompanyCollect: { // 公司收藏空
            imgName = @"no_company_icon";
            text = @"目前您没有关注任何公司！\n\n关注感兴趣的公司，随时了解招聘动态。";
            y = 110*Scale;
            textHeight = 60*Scale;
            self.userInteractionEnabled = YES;
            btnLbl.hidden = NO;
            btnLbl.text = @"去查看公司";
            
            UIImage *imgTemp = [UIImage imageNamed:imgName];
            yNoDataLbl = y+imgTemp.size.height+10*Scale;
        } break;
        case VCNilStatusTypeOfJobCollect: { // 职位收藏空
            imgName = @"no_data_icon";
            text = @"目前您没有收藏任何职位！\n\n找工作，我们建议您主动出击。";
            y = 110*Scale;
            textHeight = 60*Scale;
            self.userInteractionEnabled = YES;
            btnLbl.hidden = NO;
            btnLbl.text = @"去查看职位";
            
            UIImage *imgTemp = [UIImage imageNamed:imgName];
            yNoDataLbl = y+imgTemp.size.height+10*Scale;
        } break;
        case VCNilStatusTypeOfJobNoData: { // 职位列表空
            imgName = @"no_data_icon";
            text = @"暂无符合条件的职位";
            y = 190*Scale;
            textHeight = 20*Scale;
            self.userInteractionEnabled = NO;
            
            UIImage *imgTemp = [UIImage imageNamed:imgName];
            yNoDataLbl = y+imgTemp.size.height+10*Scale;
        } break;
        case VCNilStatusTypeOfCommonNoData: {
            imgName = @"no_data_icon";
            text = @"暂无数据";
            y = 170*Scale;
            textHeight = 20*Scale;
            self.userInteractionEnabled = NO;
            
            UIImage *imgTemp = [UIImage imageNamed:imgName];
            yNoDataLbl = y+imgTemp.size.height+10*Scale;
        } break;
        case VCNilStatusTypeOfCommonOperationError: {
            imgName = @"no_net_icon";
            text = @"网络出错，请重试";
            y = 60*Scale;
            textHeight = 20*Scale;
            self.userInteractionEnabled = YES;
            
            UIImage *imgTemp = [UIImage imageNamed:imgName];
            yNoDataLbl = y+imgTemp.size.height*0.5+10*Scale;
        } break;
        default:
            break;
    }
    
    UIImage *img = [UIImage imageNamed:imgName];
    noDataImgView.frame = CGRectMake((self.frame.size.width-img.size.width)*0.5, y, img.size.width, img.size.height);
    noDataLbl.frame = CGRectMake(0, yNoDataLbl, WIDTH, textHeight);
    btnLbl.frame = CGRectMake(110*Scale, EndY(noDataLbl)+15*Scale, self.frame.size.width-220*Scale, 50*Scale);
    
    noDataImgView.image = img;
    noDataLbl.text = text;
}

@end
